@extends('layout.default')

@section('layout.content')

  <div class="row">    
    <div class="col-xs-12">
      <table class="table table-hover table-striped table-bordered nonborder">
        <thead>
        <tr>
          <th class="align-middle">活动名称</th>
          <th class="center">类型</th>
          <th class="center">题目数 / 题库池</th>
          <th class="center">出题类型</th>
          <th class="center">答题人数</th>
          <th class="center">状态</th>
          <th class="center">创建日期</th>
        </tr>
        </thead>
        <tbody>   
          <tr class="bank">
            <td class="align-middle"><a href="{{route('exam.item', $warehouse->id)}}">{{ $warehouse->name }}</a></td>
            <td class="center">{!! $warehouse->present()->nameType !!}</td>
            <td class="center">{{ $warehouse->number }} / {{ count($warehouse->items) }}</td>
            <td class="center">{!! $warehouse->present()->nameSequence !!}</td>
            <td class="center">{{ count($warehouse->users) }}</td>
            <td class="center">{!! $warehouse->present()->nameStatus !!}</td>
            <td class="center"><span class="grey smaller-80">{{ date('Y-m-d',strtotime($warehouse->created_at)) }}</span></td>
          </tr>
        </tbody>
      </table>
    </div>

  </div>

  <div class="row">    
    <div class="col-xs-12">       
      <h5 class="header smaller lighter blue">题库</h5>
      <form class="form-horizontal" id="exam-item" autocomplete="off">
        <input type="hidden" name="warehouse" value="{{$warehouse->id}}">
        <table class="table table-hover table-striped table-bordered nonborder">
          <thead>
          <tr>
            <th class="align-center" style="width:45px;"> </th>
            <th class="align-left">题目</th>
            <th class="center" style="width:70px;">选项数</th>
            <th class="center" style="width:90px;">创建时间</th>
          </tr>
          </thead>
          <tbody>
            @foreach ($questions as $i=>$question)             
            <tr class="bank">
              <td class="align-center">
                <label class="inline no-padding-left">
                  <input name="items" type="checkbox" data-id="{{ $question->id }}" class="ace ace-checkbox-2" {{$question->selected==false?:'checked'}}>
                  <span class="lbl "> </span>
                </label>
              </td>
              <td class="align-left"><a href="{{route('question.edit',$question->id)}}">{{ $question->title }}</a></td>
              <td class="center">{{ $question->options->count() }}</td>
              <td class="center"><span class="grey smaller-80">{{ date('Y-m-d',strtotime($question->created_at)) }}</span></td>
            </tr>          
            @endforeach
          </tbody>
        </table>

        <div class="form-group">
          <div class="col-sm-12">
            <button type="button" class="btn btn-lg btn-primary submit">
              <i class="ace-icon fa fa-check"></i>
              <span class="">题目选定</span>
            </button>
          </div>
        </div>

      </form>

    </div>
  </div><!-- /.row -->
  
    
@stop
@section('javascript')  
<script type="text/javascript">
$(function () {
      
    $('.submit').on('click', function () {

        var uri = "{{route('exam.select',$warehouse->id)}}";

        var items = [];
        $("input[name='items']:checked").each(function(i){
          items[i] = $(this).data('id');
        });
        console.log(items);
        //var uri = '/exam/item/{{$warehouse->id}}';

        $.post(uri, {
          '_token': $("input[name='_token']").attr('value'),
          'items': items,
        }, function (data) {
          console.log(data);
          layer.msg(data.message, {shift: -1}, function () {
              if (data.status === true && data.url != null) {
                  $(window).attr('location', data.url);
              }
          });

        }, 'json').error(function (data) {
          console.log(data);
          layer.msg(data.responseJSON.message);
        });

    });

});
</script>
@stop
